﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Collections;

namespace Agresso.Interface.Layer.Domain
{
    public class jPOHeader
    {
        public int jPOheaderID;      //    [jPOheaderID] [int] NOT NULL,
        public string Client;            //[Client] [varchar](25) NULL,
        public string LegalEntity;       //[LegalEntity] [varchar](3) NULL,
        public string VslCode;      //[VslCode] [varchar](5) NULL,
        public string PoNo;//[PoNo] [varchar](20) NOT NULL,
        public DateTime PoDate;            //[PoDate] [datetime] NULL,
        public string Category;//[Category] [varchar](3) NULL,
        public string WorkOrderID;//[WorkOrderID] [varchar](50) NULL,
        public string VendorID; //[VendorID] [varchar](25) NULL,
        public string CurrencyCode;//[CurrencyCode] [varchar](3) NULL,
        public decimal CurrencyXrate;//[CurrencyXrate] [float] NULL,
        public string PaymentTerms;//[PaymentTerms] [varchar](25) NULL,
        public string PaymentMethod;//[PaymentMethod] [varchar](50) NULL,
        public string DeliveryMethod;//[DeliveryMethod] [varchar](25) NULL,
        public string DeliveryTerms;//[DeliveryTerms] [varchar](25) NULL,
        public string DeliveryLocation;//[DeliveryLocation] [varchar](255) NULL,
        public string POComments;//[POComments] [varchar](255) NULL,
        public string Responsible;//[Responsible] [varchar](80) NULL,
        public string Responsible2;//[Responsible2] [varchar](80) NULL,
        public decimal DiscountAmount;//[DiscountAmount] [float] NULL,
        public string Status;//[Status] [char](1) NULL,
        public string Voucher_Type;//[Voucher_Type] [varchar](2) NULL,
        public DateTime AddedOn;//[AddedOn] [datetime] NULL,
        public int PickedUpFlag;//[PickedUpFlag] [int] NULL,
        public DateTime PickedUpAt;//[PickedUpAt] [datetime] NULL,
        public int AgressoRowId;//[AgressoRowId] [bigint] NULL,
        public int TotalLineItems;//[TotalLineItems] [int] NULL,
        public string ExecutionID="";//[ExecutionID] [varchar](50) NULL,
        public string PO_Remark="";//[ExecutionID] [varchar](50) NULL,
        public int AgressoPoID; //[AgressoPoID] [bigint] NULL,
        public DateTime AgressoPODate; //[AgressoPODate] [datetime] NULL,
        public DateTime AgressoApvdDate; //[AgressoApvdDate] [datetime] NULL,
        public IList Details = new ArrayList();
        public IList Attachments = new ArrayList();

        public jPOHeader(SqlDataReader rd)
        {
            jPOheaderID = rd["jPOheaderID"] is DBNull ? jPOheaderID : Convert.ToInt32(rd["jPOheaderID"]);
            Client = rd["Client"] is DBNull ? Client : rd["Client"].ToString();
            LegalEntity = rd["LegalEntity"] is DBNull ? LegalEntity : rd["LegalEntity"].ToString();
            VslCode = rd["VslCode"] is DBNull ? VslCode : rd["VslCode"].ToString();
            PoNo = rd["PoNo"] is DBNull ? PoNo : rd["PoNo"].ToString();
            PoDate = rd["PoDate"] is DBNull ? PoDate : Convert.ToDateTime(rd["PoDate"]);
            Category = rd["Category"] is DBNull ? Category : rd["Category"].ToString();
            WorkOrderID = rd["WorkOrderID"] is DBNull ? WorkOrderID : rd["WorkOrderID"].ToString();
            VendorID = rd["VendorID"] is DBNull ? VendorID : rd["VendorID"].ToString();
            CurrencyCode = rd["CurrencyCode"] is DBNull ? CurrencyCode : rd["CurrencyCode"].ToString();
            CurrencyXrate = rd["CurrencyXrate"] is DBNull ? CurrencyXrate : Convert.ToDecimal(rd["CurrencyXrate"]);
            PaymentTerms = rd["PaymentTerms"] is DBNull ? PaymentTerms : rd["PaymentTerms"].ToString();
            PaymentMethod = rd["PaymentMethod"] is DBNull ? PaymentMethod : rd["PaymentMethod"].ToString();
            DeliveryMethod = rd["DeliveryMethod"] is DBNull ? DeliveryMethod : rd["DeliveryMethod"].ToString();
            DeliveryTerms = rd["DeliveryTerms"] is DBNull ? DeliveryTerms : rd["DeliveryTerms"].ToString();
            DeliveryLocation = rd["DeliveryLocation"] is DBNull ? DeliveryLocation : rd["DeliveryLocation"].ToString();
            POComments = rd["POComments"] is DBNull ? POComments : rd["POComments"].ToString();
            Responsible = rd["Responsible"] is DBNull ? Responsible : rd["Responsible"].ToString();
            Responsible2 = rd["Responsible2"] is DBNull ? Responsible2 : rd["Responsible2"].ToString();
            DiscountAmount = rd["DiscountAmount"] is DBNull ? DiscountAmount : Convert.ToDecimal(rd["DiscountAmount"]);
            Status = rd["Status"] is DBNull ? Status : rd["Status"].ToString();
            Voucher_Type = rd["Voucher_Type"] is DBNull ? Voucher_Type : rd["Voucher_Type"].ToString();
            AddedOn = rd["AddedOn"] is DBNull ? AddedOn : Convert.ToDateTime(rd["AddedOn"]);
            PickedUpFlag = rd["PickedUpFlag"] is DBNull ? PickedUpFlag : Convert.ToInt32(rd["PickedUpFlag"]);
            PickedUpAt = rd["PickedUpAt"] is DBNull ? PickedUpAt : Convert.ToDateTime(rd["PickedUpAt"]);
            AgressoRowId = rd["AgressoRowId"] is DBNull ? AgressoRowId : Convert.ToInt32(rd["AgressoRowId"]);
            TotalLineItems = rd["TotalLineItems"] is DBNull ? TotalLineItems : Convert.ToInt32(rd["TotalLineItems"]);
            ExecutionID = rd["ExecutionID"] is DBNull ? ExecutionID : rd["ExecutionID"].ToString();
            AgressoPoID = rd["AgressoPoID"] is DBNull ? AgressoPoID : Convert.ToInt32(rd["AgressoPoID"]);
            AgressoPODate = rd["AgressoPODate"] is DBNull ? AgressoPODate : Convert.ToDateTime(rd["AgressoPODate"]);
            AgressoApvdDate = rd["AgressoApvdDate"] is DBNull ? AgressoApvdDate : Convert.ToDateTime(rd["AgressoApvdDate"]);
            try
            {
                //error test catch UAT
                PO_Remark = rd["PO_Remark"] is DBNull ? PO_Remark : rd["PO_Remark"].ToString();
            }
            catch { }
        }
        public jPOHeader(SqlDataReader rd, bool updateDate)
        {
            PoNo = rd["PoNo"] is DBNull ? PoNo : rd["PoNo"].ToString();
            Client = rd["Client"] is DBNull ? Client : rd["Client"].ToString();
            AgressoPoID = rd["AgressoPoID"] is DBNull ? AgressoPoID : Convert.ToInt32(rd["AgressoPoID"]);
            AgressoApvdDate = rd["Agressoapvddate"] is DBNull ? AgressoApvdDate : Convert.ToDateTime(rd["AgressoApvdDate"]);
            if (AgressoApvdDate < new DateTime(2000, 1, 1))
                AgressoApvdDate = new DateTime(2000, 1, 1);
        }
    }
}
